<?php include('../includes/db_connect.php'); 
include('../includes/phpheader.php');
$id = $_POST["id"];
if(!$id) {
	$id = 0;
}
$userId = $_SESSION['user_id'];

$dateMonth = $_POST["dateMonth"];
$dateDay = $_POST["dateDay"];
$dateYear = $_POST["dateYear"];
$date = $dateYear."-".$dateMonth."-".$dateDay;

$minutes = $_POST["minutes"];
$irType = $_POST["irType"];

$sent = $_POST["sent"];
if(!$sent)		$sent=0; 		else 	$sent=1;
$sentInfo = $_POST["sentInfo"];
$sentAgency = $_POST["sentAgency"];
$sentMinutes = $_POST["sentMinutes"];

$refer = $_POST["refer"];
if(!$refer)		$refer=0; 		else 	$refer=1;
$referInfo = $_POST["referInfo"];
$referAgency = $_POST["referAgency"];
$referMinutes = $_POST["referMinutes"];

$info = $_POST["info"];
if(!$info)		$info=0; 		else 	$info=1;
$infoInfo = $_POST["infoInfo"];
$infoAgency = $_POST["infoAgency"];
$infoMinutes = $_POST["infoMinutes"];

$outcomeHealthcare = $_POST["outcomeHealthcare"];
if(!$outcomeHealthcare)		$outcomeHealthcare=0; 		else 	$outcomeHealthcare=1;
$outcomeTransportation = $_POST["outcomeTransportation"];
if(!$outcomeTransportation)		$outcomeTransportation=0; 		else 	$outcomeTransportation=1;
$outcomeAssistiveTech = $_POST["outcomeAssistiveTech"];
if(!$outcomeAssistiveTech)		$outcomeAssistiveTech=0; 		else 	$outcomeAssistiveTech=1;

$notes = $_POST["notes"];
$query = "Select max(id+1) as id from irEntry";
$result = mysql_query($query);
if($row=mysql_fetch_array($result)){
	$irId = $row["id"];
} else {
	$irId = NULL;
}

$query = "INSERT INTO `irEntry` ( `id` , `consumer_id` , `date` , `type_id` , `minutes` , `sent` , `sent_info` , `sent_agency` , `sent_minutes` , `refer` , `refer_info` , `refer_agency` , `refer_minutes` , `info` , `info_info` , `info_agency` , `info_minutes` , `outcome_healthcare` , `outcome_transportation` , `outcome_assistive_tech` , `notes` , `entered_by` )
VALUES (
$irId , $id , '$date', '$irType', '$minutes', '$sent', '$sentInfo', '$sentAgency', '$sentMinutes', '$refer', '$referInfo', '$referAgency', '$referMinutes', '$info', '$infoInfo', '$infoAgency', '$infoMinutes', '$outcomeHealthcare', '$outcomeTransportation', '$outcomeAssistiveTech', '$notes', '$userId');";

if(mysql_query($query)) {
  //echo "Success <br/>".$query;
	if($id > 0) {
		//echo "<a href=\"../admin.php?action=cieedit&id=".$id."&form=monthlyISR&isrId=0\">url</a>";
		header("Location: ../admin.php?action=cieedit&id=".$id."&form=monthlyISR&isrId=0&irId=".$irId);
	} else {
		header("Location:../admin.php?action=cieedit&id=".$id."&Status=Entry of I and R notes was successful.  Please conduct a new intake for individual if needed.");
	}
  exit();	
	
} else {
  header("Location:../admin.php?action=cieedit&id=".$id."&Error=Unable to process this I-R form due to system error.  Please contact system administrator.");
  exit();
	//echo "Failure <br/>".$query;
}
?>